package com.xuce.nzshopuserweb.config;

import com.xuce.constant.CookieConstant;
import com.xuce.constant.TokenConstant;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 徐策
 * @date 2020/3/18 23:21
 */
public class FeignConfig implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        //添加token
        requestTemplate.header(CookieConstant.USER_LOGIN, request.getHeader(CookieConstant.USER_LOGIN));
    }
}
